import type { SysRole } from '@nbase/db';
import type { IPaginationResponse, IRole } from '@nbase/shared';

/**
 * SysRole -> IRole 映射（对外返回使用）
 */
export function toRole(role: SysRole): IRole {
  return {
    id: role.id,
    code: role.code,
    name: role.name,
    status: role.status,
    description: role.description,
    createdAt: role.createdAt?.toISOString(),
    updatedAt: role.updatedAt?.toISOString(),
  };
}

/**
 * 分页结果 SysRole -> IRole
 */
export function toRolePage(page: IPaginationResponse<SysRole>): IPaginationResponse<IRole> {
  return {
    ...page,
    items: page.items.map(toRole),
  };
}

